<?php 
namespace Admin\Controller;

use Utuo\BackgroundController;

class ScoreEventController extends BackgroundController {
	
	private $status = array(
			'0' => '关闭',
			'1' => '开启'
	);
	
	public function _initialize() {
		$this->setControllerTitle('用户积分项管理');
		$this->setActionTitle(array(
				'index' => '用户积分项列表',
				'add' => '添加用户积分项',
				'modify' => '修改用户积分项',
				'recycle' => '回收站'
		));
		$this->setActionNav(array(
				'index',
				'add',
				'recycle'
		));
	}
	
	public function getLists( $is_deleted ) {
		$page = $this->getPage();
		$pagesize = $this->getPageSize();
		$pid = I('pid', 0, 'intval');
		$scoreEventLists = M('ScoreEvent')->where("status=1 and is_deleted=$is_deleted")->limit($pagesize)->page($page)->select();
		$scoreEventCount = M('ScoreEvent')->where("status=1 and is_deleted=$is_deleted")->count();
		$this->assign('scoreEventLists', $scoreEventLists);
		$this->showPage($scoreEventCount, $pagesize);
		$this->display();
	}
	
	// 活动添加
	public function addAction() {
		$scoreEvent = array();
		$scoreEvent['statusRadio'] = $this->getRadio("status", $this->status, 1);
		$this->assign("scoreEvent", $scoreEvent);
		$this->display("save");
	}
	
	public function modifyAction() {
		$activityClass = $this->getOneById("ScoreEvent");
		$activityClass['statusRadio'] = $this->getRadio("status", $this->status, $activityClass['status']);
		$this->assign("scoreEvent", $activityClass);
		$this->display("save");
	}
	
	// 活动保存
	public function saveAction() {
		$id = I("id", 0, "intval");
		$d = D("ScoreEvent");
		if($d->create()) {
			$result = !empty($d->id) ? $d->save() : $d->add();
		}
		$result !== false and $this->ajaxSuccess("保存成功");
		$this->ajaxError("保存失败");
	}
	
}
?>